/***
Common JS for global function
@author zhaidw
@ required JQuery 1.5.*
**/

app.msg = {};

app.msg.textRequestFailed 	= '系统异常，请重新查询';
app.msg.textDataLoading 	= '数据正在载入...';
app.msg.textNoDataFound 	= '当前的查询条件下无数据';
app.msg.textInitQuery 		= '请点击查询按钮';

app.page = {};
app.page.query_once = 1;
app.page.custom_column_rel = "custom_column_rel";
app.page.query_button_rel = "query_button_rel";

function query_button_control(){
	
	if(app.page.query_once == 1){
		$("input[rel='custom_column_rel']").attr("disabled","disabled");
		$("input[rel='query_button_rel']").attr("disabled","disabled");
		
		app.page.query_once = 0;
	}else{
		$("input[rel='custom_column_rel']").removeAttr("disabled");
		$("input[rel='query_button_rel']").removeAttr("disabled");
		
		app.page.query_once = 1;
	}
	
}




function app_check_null_value(columnText){
	if(columnText=="" || columnText=="-"){
		return false;
	}else{
		return true;
	}
	
}


/*
 * 页面指标展示格式化方法
 * scolumnCode 指标编码
 * columnText 指标内容
 * 返回转换好的指标值
 * by wangbo
 */
function app_column_value_format(columnCode,columnText){
	if(!app_check_null_value(columnText)){//如果列为空，不进行处理
		return columnText;
	}
	//判断列名
	if(columnCode==app.column.clm_ctr 
    || columnCode==app.column.clm_rgs_rt
    || columnCode==app.column.clm_new_rt
	|| columnCode==app.column.clm_rt
	|| columnCode==app.column.clm_rp_bt
	|| columnCode==app.column.clm_clk_cvs
	|| columnCode==app.column.clm_order_cvs
	|| columnCode==app.column.clm_clk_cvs
	|| columnCode==app.column.clm_csm_rate
	|| columnCode==app.column.clm_clk_rate
	|| columnCode==app.column.clm_rgs_trt
	|| columnCode==app.column.clm_order_ct_tr
	|| columnCode==app.column.clm_order_chr_tr

	){
		columnText = app_column_value_format_percent(columnText);
	}else{
		if(columnCode != app.column.clm_date && columnCode != 'order_time' && columnCode != 'action_time' && columnCode != 'reportdate'){
			columnText = app_column_value_format_fix(columnText);
		}
	}
	
	//app_log("convert columnCode:"+columnCode+" columnText:"+columnText);
	return columnText;
}

/*
 * 页面数据格式化 tofix(2)取精度
 * columnText 指标内容
 * 返回转换好的指标值
 * by zhangyadong
 */
function app_column_value_format_fix(columnText){
	//定义返回值
			
	var returnVal = '';
	if(!app_check_null_value(columnText)){//如果列为空，不进行处理
		return columnText;
	}
	try{
			if(isNaN(Number(columnText))){
				returnVal = columnText;
			}else{
				var numberVal = Number(columnText).toString();
				var tempFloatVal;
				var tempIntVal;
				var intVal;
				var tempIntVal;
				
				intVal = parseInt(numberVal,10).toString();
				
				if(intVal.length == numberVal.length){
					returnVal = parseFloat(numberVal).toFixed(0);
				}else{
					returnVal = parseFloat(numberVal).toFixed(2);
				}
				
			}
}catch(e){
	//记录日志
	app_log(e.message);
	returnVal = columnText;
}
	
	return returnVal;
}

/*
 * 页面数据格式化 百分比数值
 * columnText 指标内容
 * 返回转换好的指标值
 * by zhangyadong
 */
function app_column_value_format_percent(columnText){
	//定义返回值
	var returnVal = '';
	if(!app_check_null_value(columnText)){//如果列为空，不进行处理
		return columnText;
	}
	try{
		returnVal = (parseFloat(columnText)*100).toFixed(2) + "%";
		}catch(e){
			//记录日志
			app_log(e.message);
			returnVal = columnText;
		}
	
	return returnVal;
}


//查询条件过滤结果数据量超载的错误代码
app.query_exceed_max_error_code = "416";
app.query_exceed_null_error_code = "204";
app.query_exceed_null_data_error_code = "421";

app.mask_id 	= '__div_query_mask';
app.masker_id 	= '__div_query_masker';
app.mask_height_time = '';

function app_adjust_mask_height(){
	var htmlObj = $(document.body);
	
	$('#' + app.mask_id ).css({"height": htmlObj.height(), "width" : htmlObj.width()});
};

$(function() {
	
	//异步请求全局设置 10 分钟
	$.ajaxSetup({
		type: "POST",
		timeout: 600000
	});


});
